package com.hzy.es.service.impl;

import com.hzy.es.entity.Item;
import com.hzy.es.repository.ItemRepository;
import com.hzy.es.service.ItemService;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.Optional;

@Service
public class ItemServiceImpl implements ItemService {

    @Resource
    private ItemRepository itemRepository;

    public void test(){
        Iterable<Item> all = itemRepository.findAll();
        Iterator<Item> it = all.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        Optional<Item> byId = itemRepository.findById(1L);
        Item item = byId.get();
        System.out.println(item);

        boolean exists = itemRepository.existsById(1L);
        System.out.println(exists);
    }
}
